package net.sf.odinms.exttools.doclet.pages;

import java.io.IOException;
import net.sf.odinms.exttools.doclet.Doclet;

/**
 * Creates "overview-tree.html", a hierarchy of all documented classes.
 */
public final class OverviewTree extends AbstractTree {
	
	/**
	 * Create the page with the hierarchy of all packages and classes.
	 */
	public static void generateOverviewTree() {
		if (!CONF.createtree)
			return;
		String filename = "overview-tree" + CONF.ext;
		try {
			new OverviewTree(filename);
		}
		catch (IOException exc) {
			throw Doclet.exception(exc, filename);
		}
	}
	
	/**
	 * Initialize filename and page type for tree of all packages.
	 * 
	 * @param filename The desired name of the file (with extension).
	 * @throws IOException If {@link java.io.FileOutputStream} creation fails.
	 */
	private OverviewTree(String filename) throws IOException {
		super(filename);
		pageType = PageType.OVERVIEW_TREE;
		
		windowTitle = "Class Hierarchy";
		
		printXhtmlHeader();
		println(open("h1") + CONF.propertyText("Hierarchy_For_All_Packages")
				+ close("h1"));
		
		// Do nothing if only unnamed package is used
		if ((packages.length != 1 || packages[0].name().length() > 0)
				&& !classesOnly) {
			println(openDivWithID("Overview"));
			println(open("dl"));
			println(open("dt") + CONF.propertyText("Package_Hierarchies")
					+ close("dt"));
			print(open("dd") + open("ul"));
			
			for (com.sun.javadoc.PackageDoc pkg : packages) {
				if (pkg.name().length() > 0)
					println(listItem(linkToLabelHref(pkg.name(),
							pathToPackageFile(pkg, "package-tree" + CONF.ext))));
			}
			print(close("ul") + close("dd"));
			println(close("dl"));
			println(close("div") + getComment("#Overview"));
		}
		printMemberSubgroups();
		
		printXhtmlFooter();
		this.close();
	}
	
}
